package com.xbongbong.rule.builder;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.rule.engine.XbbRuleEngine;
import com.xbongbong.rule.rules.XbbRule;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 规则引擎构建器
 * 目前只用到如下三个参数,且类型固定为JsonObject,后续如有需求可再优化
 *
 * @author LiZhikang
 * @date 2023/3/29 14:50
 */
@Data
@Accessors(chain = true)
public class XbbRuleEngineBuilder {
    /**
     * 是否匹配到一组规则就停止
     */
    private boolean skipOnFirstAppliedRule;
    /**
     * 规则列表
     */
    private List<XbbRule<JSONObject>> xbbRules;
    /**
     * 待校验数据
     */
    private JSONObject data;

    /**
     * 规则引擎构建
     * @return
     */
    public XbbRuleEngine<JSONObject> build() {
        XbbRuleEngine<JSONObject> xbbRuleEngine = new XbbRuleEngine<>();
        xbbRuleEngine.setSkipOnFirstAppliedRule(skipOnFirstAppliedRule);
        xbbRuleEngine.setXbbRules(xbbRules);
        xbbRuleEngine.setXbbFact(data);
        xbbRuleEngine.build();
        return xbbRuleEngine;
    }
}
